<template>
  <view class="receipt-container">
    <!-- 顶部导航 -->
    <view class="nav-header">
      <view class="nav-back" @click="goBack">
        <text class="back-icon">‹</text>
      </view>
      <text class="nav-title">选择身份</text>
      <view class="nav-placeholder"></view>
    </view>

    <!-- 主要内容 -->
    <view class="main-content">
      <!-- 顶部蓝色区域 -->
      <view class="top-section">
        <view class="decorative-circles">
          <view class="circle circle-1"></view>
          <view class="circle circle-2"></view>
          <view class="circle circle-3"></view>
        </view>
        <view class="title-area">
          <text class="main-title">请选择您的角色</text>
          <text class="sub-title">选择合适的身份开始创建合同</text>
        </view>
        <view class="illustration">
          <image
            class="illustration-img"
            src="/static/contract.png"
            mode="aspectFit"
          ></image>
        </view>
      </view>

      <!-- 角色选择区域 -->
      <view class="role-selection">
        <!-- 出借人角色 -->
        <view class="role-card lender-card" @click="selectRole('lender')">
          <view class="role-icon">
            <view class="icon-bg"></view>
            <image
              class="icon-img"
              src="/static/lender-icon.png"
              mode="aspectFit"
            ></image>
          </view>
          <view class="role-info">
            <text class="role-title">出借人</text>
            <text class="role-desc">别人欠我钱</text>
            <view class="role-tags">
              <text class="tag">债权人</text>
            </view>
          </view>
          <view class="role-arrow">
            <text class="arrow">›</text>
          </view>
        </view>

        <!-- 借款人角色 -->
        <view class="role-card borrower-card" @click="selectRole('borrower')">
          <view class="role-icon">
            <view class="icon-bg"></view>
            <image
              class="icon-img"
              src="/static/borrower-icon.png"
              mode="aspectFit"
            ></image>
          </view>
          <view class="role-info">
            <text class="role-title">借款人</text>
            <text class="role-desc">我欠别人钱</text>
            <view class="role-tags">
              <text class="tag">债务人</text>
            </view>
          </view>
          <view class="role-arrow">
            <text class="arrow">›</text>
          </view>
        </view>
      </view>

      <!-- 说明文字 -->
      <view class="description">
        <text class="desc-text"
          >选择您的身份后，系统将为您生成相应的合同模板</text
        >
      </view>

      <!-- 功能特点 -->
      <view class="features">
        <view class="feature-item">
          <view class="feature-icon">
            <text class="icon">📋</text>
          </view>
          <text class="feature-text">智能模板</text>
        </view>
        <view class="feature-item">
          <view class="feature-icon">
            <text class="icon">🔒</text>
          </view>
          <text class="feature-text">安全可靠</text>
        </view>
        <view class="feature-item">
          <view class="feature-icon">
            <text class="icon">⚡</text>
          </view>
          <text class="feature-text">快速生成</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from "vue";

// 返回上一页
const goBack = () => {
  uni.navigateBack();
};

// 选择角色
const selectRole = (roleType) => {
  // 判断当前用户是否登录
  const token = uni.getStorageSync("token");
  if (!token) {
    // 弹窗提示是否去登录
    uni.showModal({
      title: '提示',
      content: '您还未登录，是否前往登录？',
      success: (res) => {
        if (res.confirm) {
          uni.navigateTo({
            url: '/pages/login/index'
          });
        }
      }
    });
    return;
  }
  const userInfo = uni.getStorageSync("userInfo");
  if (userInfo.status == 3) {
    // 这里可以添加导航到下一页的逻辑
    uni.navigateTo({
      url: `/pages/borrow/contract?borrowerType=${roleType}`,
    });
  }else{
    // 弹窗提示 点击确认去认证
    uni.showModal({
      title: '提示',
      content: '您还未实名认证，是否前往认证？',
      success: (res) => {
        if (res.confirm) {
          uni.navigateTo({
            url: '/pages/mine/profile'
          });
        }
      }
    });
  }
};
</script>

<style scoped>
.receipt-container {
  min-height: 100vh;
  background: linear-gradient(180deg, #f8f9ff 0%, #f0f2f8 100%);
}

/* 顶部导航 */
/* 顶部导航 */
.nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20rpx 30rpx;
  padding-top: calc(var(--status-bar-height) + 20rpx);
  background: #ffffff;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-back {
  width: 60rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #f8f9fa;
}

.back-icon {
  font-size: 36rpx;
  color: #333;
  font-weight: bold;
}

.nav-title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
}

.nav-placeholder {
  width: 60rpx;
}

/* 主要内容 */
.main-content {
  position: relative;
}

/* 顶部蓝色区域 */
.top-section {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 60rpx 30rpx 120rpx;
  position: relative;
  overflow: hidden;
  background-size: 400% 400%;
  animation: gradientShift 8s ease infinite;
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* 装饰圆圈 */
.decorative-circles {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  animation: float 6s ease-in-out infinite;
}

.circle-1 {
  width: 120rpx;
  height: 120rpx;
  top: 20%;
  right: 10%;
  animation-delay: 0s;
}

.circle-2 {
  width: 80rpx;
  height: 80rpx;
  top: 60%;
  left: 15%;
  animation-delay: 2s;
}

.circle-3 {
  width: 60rpx;
  height: 60rpx;
  top: 40%;
  right: 30%;
  animation-delay: 4s;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0rpx) scale(1);
    opacity: 0.6;
  }
  50% {
    transform: translateY(-20rpx) scale(1.1);
    opacity: 0.3;
  }
}

.title-area {
  text-align: center;
  margin-bottom: 50rpx;
  position: relative;
  z-index: 2;
  animation: slideInDown 0.8s ease-out;
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-30rpx);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.main-title {
  display: block;
  font-size: 48rpx;
  font-weight: bold;
  color: #ffffff;
  text-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.3);
  letter-spacing: 2rpx;
  margin-bottom: 16rpx;
}

.sub-title {
  display: block;
  font-size: 28rpx;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 400;
}

.illustration {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 2;
  animation: slideInUp 0.8s ease-out 0.3s both;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30rpx);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.illustration-img {
  width: 300rpx;
  height: 200rpx;
  border-radius: 30rpx;
}

/* 角色选择区域 */
.role-selection {
  padding: 0 30rpx;
  margin-top: -80rpx;
  position: relative;
  z-index: 3;
}

.role-card {
  background: #ffffff;
  border-radius: 24rpx;
  padding: 32rpx;
  margin-bottom: 24rpx;
  display: flex;
  align-items: center;
  box-shadow: 0 8rpx 40rpx rgba(0, 0, 0, 0.08);
  transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  border: 3rpx solid transparent;
  position: relative;
  overflow: hidden;
  animation: slideInCard 0.6s ease-out;
}

@keyframes slideInCard {
  from {
    opacity: 0;
    transform: translateY(40rpx);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.lender-card {
  animation-delay: 0.4s;
  animation-fill-mode: both;
}

.borrower-card {
  animation-delay: 0.6s;
  animation-fill-mode: both;
}

.role-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(102, 126, 234, 0.1),
    transparent
  );
  transition: left 0.6s ease;
}

.role-card:active {
  transform: translateY(2rpx) scale(0.98);
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}

.role-card:active::before {
  left: 100%;
}

.role-icon {
  width: 100rpx;
  height: 100rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 24rpx;
  margin-right: 30rpx;
  position: relative;
  overflow: hidden;
}

.icon-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 24rpx;
  animation: iconPulse 2s ease-in-out infinite;
}

@keyframes iconPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.icon-img {
  width: 60rpx;
  height: 60rpx;
  filter: brightness(0) invert(1);
  position: relative;
  z-index: 2;
}

.role-info {
  flex: 1;
}

.role-title {
  display: block;
  font-size: 34rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 8rpx;
}

.role-desc {
  display: block;
  font-size: 26rpx;
  color: #666;
  margin-bottom: 12rpx;
}

.role-tags {
  display: flex;
  gap: 8rpx;
}

.tag {
  font-size: 22rpx;
  color: #667eea;
  background: rgba(102, 126, 234, 0.1);
  padding: 4rpx 12rpx;
  border-radius: 12rpx;
  border: 1rpx solid rgba(102, 126, 234, 0.2);
}

.role-arrow {
  width: 40rpx;
  height: 40rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(102, 126, 234, 0.1);
  border-radius: 50%;
  transition: all 0.3s ease;
}

.role-card:active .role-arrow {
  background: #667eea;
}

.arrow {
  font-size: 28rpx;
  color: #667eea;
  font-weight: bold;
  transition: all 0.3s ease;
}

.role-card:active .arrow {
  color: #ffffff;
  transform: translateX(2rpx);
}

/* 说明文字 */
.description {
  display: flex;
  justify-content: center;
  animation: fadeIn 1s ease-out 0.8s both;
  margin-bottom: 40rpx;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.desc-text {
  font-size: 26rpx;
  color: #666;
}

/* 功能特点 */
.features {
  padding: 0 30rpx 60rpx;
  display: flex;
  justify-content: space-around;
  animation: slideInUp 0.8s ease-out 1s both;
}

.feature-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  animation: bounceIn 0.6s ease-out;
}

.feature-item:nth-child(1) {
  animation-delay: 1.2s;
}
.feature-item:nth-child(2) {
  animation-delay: 1.4s;
}
.feature-item:nth-child(3) {
  animation-delay: 1.6s;
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
  70% {
    transform: scale(0.9);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.feature-icon {
  width: 80rpx;
  height: 80rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(
    135deg,
    rgba(102, 126, 234, 0.1) 0%,
    rgba(118, 75, 162, 0.1) 100%
  );
  border-radius: 50%;
  margin-bottom: 16rpx;
  border: 2rpx solid rgba(102, 126, 234, 0.2);
  transition: all 0.3s ease;
}

.feature-item:hover .feature-icon {
  transform: scale(1.1);
  background: linear-gradient(
    135deg,
    rgba(102, 126, 234, 0.2) 0%,
    rgba(118, 75, 162, 0.2) 100%
  );
}

.icon {
  font-size: 36rpx;
}

.feature-text {
  font-size: 24rpx;
  color: #666;
  text-align: center;
  font-weight: 500;
}

/* 响应式设计 */
@media (max-width: 750rpx) {
  .main-title {
    font-size: 42rpx;
  }

  .sub-title {
    font-size: 24rpx;
  }

  .role-card {
    padding: 24rpx;
  }

  .role-icon {
    width: 80rpx;
    height: 80rpx;
    margin-right: 20rpx;
  }

  .icon-img {
    width: 48rpx;
    height: 48rpx;
  }

  .role-title {
    font-size: 30rpx;
  }

  .role-desc {
    font-size: 24rpx;
  }
}

/* 暗色模式适配 */
@media (prefers-color-scheme: dark) {
  .receipt-container {
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
  }

  .role-card {
    background: #2d3748;
    border-color: #4a5568;
  }

  .role-title {
    color: #e2e8f0;
  }

  .role-desc {
    color: #a0aec0;
  }

  .desc-text {
    color: #a0aec0;
    background: rgba(102, 126, 234, 0.1);
  }

  .feature-text {
    color: #a0aec0;
  }
}
</style>
